namespace Vin.Extension.Redis.Service;

public class RedisMapService : BaseRedisService
{
    public async Task<bool> SetAsync<T>(string key, string? field, T value, TimeSpan? expireTime = null, int db = 0,
        bool bothway = false)
    {
        if (bothway)
        {
            await GetRedisCache(db).SetHashCacheAsync(key, value!.ToString(), field, expireTime);
        }

        await GetRedisCache(db).SetHashCacheAsync(key, field, value, expireTime);

        return true;
    }

    // public Task<bool> SetAsync<T>(string key, string? field, T value, TimeSpan? expireTime = null, int db = 0)
    // {
    //     return GetRedisCache(db).SetHashCacheAsync(key, field, value, expireTime);
    // }

    public Task<bool> SetAsync<T>(string key, Dictionary<string, T> values, TimeSpan? expireTime = null, int db = 0)
    {
        return GetRedisCache(db).SetHashCacheAsync(key, values, expireTime);
    }

    public Task<T?> GetAsync<T>(string key, string field, int db = 0)
    {
        return GetRedisCache(db).GetHashCacheAsync<T>(key, field);
    }

    public Task<bool> ExistsAsync(string key, string field, int db = 0)
    {
        return GetRedisCache(db).HashExistsAsync(key, field);
    }
}